package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/29 22:32
 **/
public class Day28_6_Num191_HammingWeight {
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int ans = 0;
            int i = 32;
            while(i-- > 0){
                if((n & 1) == 1)
                    ans ++;

                n >>= 1;
            }
            return ans;
        }
    }
}